﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using VirtualTournaments.Services.Tournaments;
using VirtualTournaments.Frontend.MenuControls.TournamentManagerMenu.InnerControls;
using System.Collections.Generic;

namespace VirtualTournaments.Frontend.MenuControls.GenericControls
{
    using Match = Services.Tournaments.Match;

    public partial class JourneyManager : System.Web.UI.UserControl
    {
        public FontUnit FontSize
        {
            get;
            set;
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            //Match[] JourneyMatches = (Match[])Session["CurrentJourneyMatches"];
            if (Session["CurrentJourneyMatches"] != null)
            {
            Journey journey = (Journey)Session["CurrentJourneyMatches"];
            Match[] JourneyMatches = journey.Matches.ToArray();
            if (JourneyMatches != null)
            {
                MatchesTable.Rows.Clear();

                TableRow matchRow;
                TableCell matchCell;

                foreach (Match match in JourneyMatches)
                {
                    matchRow = new TableRow();
                    matchCell = new TableCell();
                    Label label = new Label();
                    if (FontSize == null)
                        label.Font.Size = FontUnit.Medium;
                    else
                        label.Font.Size = FontSize;
                    label.Text = match.Local;

                    if (Session["MatchesPlayed"] != null)
                    {
                        bool played = (bool)Session["MatchesPlayed"];
                        if (played)
                            label.Text += " " + match.LocalGoals + " : " + match.VisitorGoals + " ";
                        else
                            label.Text += " vs. ";
                        
                    }
                    else 
                    {
                        if (match.Played)
                            label.Text += " " + match.LocalGoals + " : " + match.VisitorGoals + " ";
                        else
                            label.Text += " vs. ";
                    }

                    label.Text += match.Visitor + "<br />";
                    matchCell.Controls.Add(label);
                    matchRow.Cells.Add(matchCell);
                    MatchesTable.Rows.Add(matchRow);
                }
            }
            }
        }
        
        protected void NextWeekButton_OnClick(object sender, EventArgs e)
        { 
            //if (WeekViews.ActiveViewIndex < (WeekViews.Views.Count - 1))
            //{
            //    WeekViews.ActiveViewIndex++;
            //    WeekHeaderCell.Text = "Week " + (WeekViews.ActiveViewIndex + 1); 
            //}
        }

        protected void PreviousWeekButton_OnClick(object sender, EventArgs e)
        { 
            //if (WeekViews.ActiveViewIndex > 0)
            //{
            //    WeekViews.ActiveViewIndex--;
            //    WeekHeaderCell.Text = "Week " + (WeekViews.ActiveViewIndex + 1); 
            //}
        }
    }
}